#!/usr/bin/python2.4
#
# Copyright 2011 Google Inc. All Rights Reserved.

from google.appengine.dist import use_library
from git.util import git_context
use_library('django', '1.2')
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from db import user
from libs import login_util

import os
import urllib

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

class MainPage(webapp.RequestHandler):
    def post(self):
        email = self.request.get('email')
        
        has_user = user.HasUser(email)
        if has_user:
            session_manager = git_context.GitContext.GetSessionManager()
            session_manager.SetSessionAccount(None)
            self.redirect('/')
        else:
            self.redirect('/staticpages/error.html?msg=' + \
                          urllib.quote('No user in database to sign out!'))
    def get(self):
        session_manager = git_context.GitContext.GetSessionManager()
        session_manager.SetSessionAccount(None)
        self.redirect('/')


application = webapp.WSGIApplication([('/signout.do', MainPage)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()